from loguru import logger
from selenium import webdriver
from selenium.webdriver.common.by import By

from commonDemo.common_element import BaseAction


class Login(BaseAction):
    url = 'http://192.168.16.30:83/login'
    #切换账号登录
    account_login = By.XPATH, "//div[text()='账号登录']"
    username_loc = By.ID, 'username'
    password_loc = By.ID, 'password'
    button_denglu = "//button/span[text()='登 录']"
    sbmit_loc = By.XPATH, button_denglu

    def loginPDM(self):
        # chrome_options = webdriver.ChromeOptions()
        # chrome_options.add_argument("lang=zh-CN.UTF-8")
        # self.driver = webdriver.Remote(command_executor="http://192.168.16.32:5444/wd/hub",
        #                                options=chrome_options
        #                                )
        # self.driver.implicitly_wait(3)
        # 打开网址
        self.driver.get(self.url)
        logger.info("已打开登录页面")
        # 切换账号登录
        self.click(self.account_login)
        logger.info("已切换账号登录")
        # 输入用户名、密码
        self.input(self.username_loc, "admin")
        self.input(self.password_loc,"123456")
        logger.info("已输入用户名和密码")
        self.click(self.sbmit_loc)
        logger.info("已点击登录按钮")

if __name__ == '__main__':
    login = Login(driver=webdriver.Chrome())
    login.loginPDM()
